TARGET = vio2display

# 指定ARM64交叉编译工具链路径
TOOLCHAIN_PATH := /opt/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu
# 指定ARM64编译器（aarch64架构的gcc）
CC := $(TOOLCHAIN_PATH)/bin/aarch64-none-linux-gnu-gcc
# 指定ARM64链接器（aarch64架构的ld，可选，gcc通常会自动调用）
LD := $(TOOLCHAIN_PATH)/bin/aarch64-none-linux-gnu-ld

SRC_PATH := $(CURDIR)




CFLAGS += -I$(SRC_PATH)/../clang  # 当前目录下的include子目录
# 获取指定目录下的所有 .so 库文件
# 指定目标库目录，让链接器递归搜索所有依赖（包括版本化库）
LDFLAGS += -Wl,-rpath-link=$(SRC_PATH)/../../../deploy/rootfs/usr/lib
LDFLAGS += -Wl,-rpath-link=$(SRC_PATH)/../../../deploy/rootfs/usr/lib/aarch64-linux-gnu
LDFLAGS += -Wl,-rpath-link=$(SRC_PATH)/../../../deploy/rootfs/usr/hobot/lib/
# 只链接必要的库，无需通配符
LDFLAGS += -L$(SRC_PATH)/../../../deploy/rootfs/usr/lib -lspcdev -ldnn

SRCS := $(foreach cf, $(SRC_PATH), $(wildcard $(cf)/*.c))
OBJS :=  $(SRCS:.c=.o)

.PHONY: all clean

all: ${TARGET}

%.o:%.c
	@mkdir -p $(abspath $(dir $@))
	$(CC) -o $@ $(CFLAGS) -c $<

$(TARGET):$(OBJS)
	@mkdir -p $(abspath $(dir $@))
	$(CC) -O3 -o $@ $(OBJS) $(LDFLAGS)

clean:
	rm -rf ${OBJS} ${TARGET}
